﻿using B.Auth.APi.Application.Command.RoleMenus;
using B.Auth.Domain.Entity;
using B.Auth.Domain.Repository;
using B.Auth.Enum;
using MediatR;
using Microsoft.EntityFrameworkCore;

namespace B.Auth.APi.Application.CommandHand.RoleMenu
{
    public class GetMenuIdHand : IRequestHandler<GetMenuIdcommand, ApiResult<List<int>>>
    {

        private readonly IBaseRepository<RoleMenuModel> _rolemenu;

        public GetMenuIdHand(IBaseRepository<RoleMenuModel> rolemenu)
        {
            _rolemenu = rolemenu;
        }

        public Task<ApiResult<List<int>>> Handle(GetMenuIdcommand request, CancellationToken cancellationToken)
        {
            var result=new ApiResult<List<int>>();
            List<int> menuid = _rolemenu.GetAll().Where(x => x.RID == request.roldid).Select(x => x.MID).ToList();
            result.data = menuid;
           return Task.FromResult(result);


        }
    }
}
